package com.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.entity.Student;
import com.chen.service.IStudentService;
import com.chen.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class StudentController {

    @Autowired
    IStudentService studentService;



    /*
    * 分页带条件查询
    * */
    @GetMapping("/getPage")
    public ResultVo getPage(String studentname, @RequestParam(name = "pageNum",defaultValue = "1")Integer  pageNum){
        Page page=studentService.getPage(studentname,pageNum);
        return ResultVo.success("操作成功",page);
    }

    /*
    * 新增或修改
    * */
    @PostMapping("/saveOrupdate")
    public ResultVo saveOrupdate(@RequestBody Student student){
        studentService.saveOrUpdate(student);
        return ResultVo.success("",null);
    }


    /*
    * 删除
    * */
    @DeleteMapping("/del/{id}")
    public ResultVo del(@PathVariable Integer id){
        studentService.removeById(id);
        return ResultVo.success("",null);
    }
}
